<template>
  <div class="container">
    <div>
      <el-row  type="flex" :gutter="10" justify="space-between">
        <el-col :span="4">
          <el-form ref="form" :model="form" label-width="100px">
            <el-form-item label="查 询 方 式："  style="width: 250px;">
              <el-select
                v-model="form.queryType"
                placeholder="请选择"
    
              >
                <el-option
                  v-for="item in form.queryTypeList"
                  :key="item.index"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="4">
          <el-form ref="form" :model="form" label-width="100px">
            <el-form-item label="人 员 类 型："  style="width: 250px;">
              <el-select
                v-model="form.cph"
                placeholder="请选择"
                filterable
                clearable
              >
                <el-option
                  v-for="item in form.cphList"
                  :key="item.index"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="4">
          <el-form ref="form" :model="form" label-width="100px">
            <el-form-item label="开始时间(时)："  style="width: 250px;">
              <el-select
                v-model="form.StartDate"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in form.hourList"
                  :key="item.index"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="4">
          <el-form ref="form" :model="form"  style="margin-left:">
            <el-button size="mini" type="primary" @click="searchAction"
              >查 询</el-button
            >
            <el-button size="mini" type="success" @click="exportExcel"
              >导 出</el-button
            >
          </el-form>
        </el-col>
      </el-row>
      <el-row type="flex" :gutter="10" justify="space-between">
        <el-col :span="4">
          <el-form ref="form" :model="form" label-width="100px">
            <el-form-item label="出勤距离(米)："  style="width: 250px;">
              <el-input
                v-model="form.distance"
                placeholder="请输入人员出勤距离"
              ></el-input>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="4">
          <el-form ref="form" :model="form" label-width="100px">
           <el-form-item label="组 织 机 构："  style="width: 250px;">
              <el-select
                v-model="form.groupingValue"
                placeholder="请选择"
                filterable
                clearable
              >
                <el-option
                  v-for="item in form.groupingList"
                  :key="item.index"
                  :label="item.CLIENT_NAME"
                  :value="item.CLIENT_NO"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="4">
          <el-form ref="form" :model="form" label-width="100px">
            <el-form-item label="结束时间(时)："  style="width: 250px;">
              <el-select
                v-model="form.EndDate"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in form.hourList"
                  :key="item.index"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="4">
          
        </el-col>
      </el-row>
    </div>
    <el-table
      v-loading="loading"
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
      highlight-current-row
    >
      <el-table-column
        v-for="(item, index) in tableHead"
        :key="index"
        :label="item.label"
        :property="item.property"
        align="center"
      >
        <template slot-scope="scope">{{
          scope.row[scope.column.property]
        }}</template>
      </el-table-column>

      <!-- <el-table-column
        prop="GROUPNAME"
        label="所属区县"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="ALLNUM"
        label="现有人员数"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="CURRENTNUM"
        label="出勤人员数"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="currentRatio"
        label="出勤比率"
        align="center"
      ></el-table-column> -->
      <!-- <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-info" @click="handleEdit(scope.$index, scope.row)">详情</el-button>
        </template>
      </el-table-column>-->
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import '@/assets/css/common.css'
import { formatDate } from '@/common/js/date.js'

import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {

    return {
      currentPage: 1, //初始页
      pageSize: 10,    //    每页的数据
      form: {
        queryType: '0',
        queryTypeList: [{
          value: '0',
          label: '按组织机构查询'
        }, {
          value: '1',
          label: '按人员类型查询'
        }],
        distance: 500,
        groupingList: [],
        groupingValue: '',
        cphList: [{
          value: '全部',
          label: '全部'
        }, {
          value: '巡查员',
          label: '巡查员'
        // }, {
        //   value: '勾臂车',
        //   label: '勾臂车'
        }],
        cph: '全部',//车牌号
        hourList: [{
          value: '0',
          label: '0时'
        }, {
          value: '1',
          label: '1时'
        }, {
          value: '2',
          label: '2时'
        }, {
          value: '3',
          label: '3时'
        }, {
          value: '4',
          label: '4时'
        }, {
          value: '5',
          label: '5时'
        }, {
          value: '6',
          label: '6时'
        }, {
          value: '7',
          label: '7时'
        }, {
          value: '8',
          label: '8时'
        }, {
          value: '9',
          label: '9时'
        }, {
          value: '10',
          label: '10时'
        }, {
          value: '11',
          label: '11时'
        }, {
          value: '12',
          label: '12时'
        }, {
          value: '13',
          label: '13时'
        }, {
          value: '14',
          label: '14时'
        }, {
          value: '15',
          label: '15时'
        }, {
          value: '16',
          label: '16时'
        }, {
          value: '17',
          label: '17时'
        }, {
          value: '18',
          label: '18时'
        }, {
          value: '19',
          label: '19时'
        }, {
          value: '20',
          label: '20时'
        }, {
          value: '21',
          label: '21时'
        }, {
          value: '22',
          label: '22时'
        }, {
          value: '23',
          label: '23时'
        }, {
          value: '24',
          label: '24时'
        }],
        alermTypeList: [{ label: '1分钟', value: '1' }, { label: '5分钟', value: '5' }, { label: '10分钟', value: '10' }, { label: '30分钟', value: '30' }],
        alermTypeValue: '5',
        StartDate: '0',
        EndDate: new Date().getHours().toString(),
      },
      originalData: [],
      tableData: [],
      tableHead: [],
      loading: false,
      URLByTYPE: 'Worker'
    }
  },
  created () {
  },
  mounted () {
    this.getGroupingList()
  },
  methods: {
    //获取人员分组列表
    async getGroupingList () {
      var url = this.URLByTYPE + '/GetGroupList?ClientNo=' + localStorage.getItem('CLIENT_NO') // zxdata
      let { data } = await this.$Http.get(url)
      this.form.groupingList = data
      this.form.groupingValue = data[0].CLIENT_NO
      this.searchAction()
    },
    //获取车牌列表
    // async getLisencePlateList () {
    //   this.form.cph = ''
    //   var url = this.URLByTYPE + '/GetVehicleCarListSelect?ClientNo=' + this.form.groupingValue
    //   const { data } = await this.$Http.get(url)
    //   this.form.cphList = data
    //   // this.form.cphList.unshift({ "LicensePlate": "全部" })
    // },
    searchAction () {
      if (this.form.queryType === '1') {
        this.tableHead = [
          {
            label: '人员类型',
            property: 'WORKTYPE'
          }, {
            label: '现有人员数',
            property: 'ALLNUM'
          }, {
            label: '出勤人员数',
            property: 'CURRENTNUM'
          }, {
            label: '出勤比率',
            property: 'currentRatio'
          }
        ]
      } else {
        this.tableHead = [
          {
            label: '所属区县',
            property: 'GROUPNAME'
          }, {
            label: '现有人员数',
            property: 'ALLNUM'
          }, {
            label: '出勤人员数',
            property: 'CURRENTNUM'
          }, {
            label: '出勤比率',
            property: 'currentRatio'
          }
        ]
      }
      this.getlistdata()
    },
    async getlistdata () {
      this.currentPage = 1;
      this.loading = true
      // var url = 'Vehicle/GetChucheDistance?ClientNo=0000009&StartDate=2&EndDate=8&cartype=全部&juli=0.5&type=1'
      var url = this.URLByTYPE + '/GetChucheDistanceYL?StartDate=' + this.form.StartDate + '&EndDate=' + this.form.EndDate + '&cartype='+this.form.cph+'&juli=' + (this.form.distance / 1000) + '&isHadSnowCar=1&type=' + this.form.queryType + '&ClientNo=' + this.form.groupingValue
      const { data } = await this.$Http.get(url)
      data.forEach(element => {
        element.currentRatio = (element.CURRENTNUM / element.ALLNUM * 100).toFixed(2) + '%'
      });
      // 原始数据
      this.tableData = data
      this.loading = false
    },
    // 导出Excel
    exportExcel () {
      let excelName = '当日累计出勤统计'
      var tHeader = ['所属区县', '现有人员数', '出勤人员数', '出勤比率']
      var filterVal = ['GROUPNAME', 'ALLNUM', 'CURRENTNUM', 'currentRatio']
      if (this.form.queryType === '1') {
        tHeader = ['人员类型', '现有人员数', '出勤人员数', '出勤比率']
        filterVal = ['CAR_TYPE', 'ALLNUM', 'CURRENTNUM', 'currentRatio']
      }
      export2Excel(tHeader, filterVal, this.tableData, excelName)
    },
    //详情
    handleEdit (index, row) {
      //   this.idx = index;
      //   this.form = row;
      //   this.editVisible = true;
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  width: 350px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
.el-form-item label {
  width: 80px;
}
</style>